<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>websocket多终端通讯</title>
</head>
<body>
    <script>
        let ws = new WebSocket('ws://localhost:3000')

        //监听建立连接
        ws.onopen = function (res) {
            console.log('连接成功')
        }

        //监听有新消息
        ws.onmessage = function (res) {
            console.log(res.data)
        }
    </script>
</body>
</html>